#include "eventloop.h"
#include "tcpserver.h"
#include "tcpconnection.h"
#include <iostream>

void onConnection(const std::shared_ptr<TcpConnection>& conn) {
    std::cout << "New connection established" << std::endl;
}

void onMessage(const std::shared_ptr<TcpConnection>& conn, const std::string& msg) {
    std::cout << "Received: " << msg << std::endl;
    conn->send(msg);  // echo back
}

int main() {
    EventLoop loop;
    TcpServer server(&loop, "127.0.0.1", 12345);

    server.setConnectionCallback(onConnection);
    server.setMessageCallback(onMessage);

    server.start();
    loop.loop();  // 启动事件循环
    return 0;
}
